<?php
/**
 * Created by PhpStorm.
 * User: xiaomeng
 * Date: 17-9-14
 * Time: 下午3:01
 */
namespace swf\socket;

class Response
{

    static private $allow_error_msg = [
        0 => 'ok',
        1 => '请求参数缺少',
        2 => '命令不存在',
        3 => '类或者方法不存在',
        4 => '用户已经登录',
        5 => '',
        6 => '用户类型不正确',
        7 => '渠道不存在',
        8 => '分配渠道失败',
        9 => '不能重复执行初始化',
        10 => '请求参数缺少',
        11 => '不是投注时间，不允许投注',
        12 => '投注失败',
        13 => '只有投注状态才可以撤销哦',
        14 => '没有投注，无法撤销',
        15 => '已达投注上限',
        16 => '获取余额失败',
        17 => '撤销投注失败',
    ];
    static public function send($server,$fd, $cmd, $data = [], $code = 0)
    {
        $_data = json_encode(array('cmd' => $cmd, 'code' => $code, 'msg' => self::$allow_error_msg[$code], 'data'=>$data),JSON_UNESCAPED_UNICODE);
        $server->push($fd, $_data);
    }

    static public function sendAll($server,$cmd,$fds,$data,$code = 0)
    {
        foreach ($fds as $fd)
        {
            self::send($server,$fd,$cmd,$data,$code);
        }
    }
}